
package swa08.provider;

import java.io.IOException;
import java.util.Properties;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.ServletConfig;

import org.apache.cxf.transport.servlet.CXFNonSpringServlet;

public class Servlet extends CXFNonSpringServlet
{
	private static final long serialVersionUID = 1L;
	private ServiceImpl service;

	@Override
    protected void loadBus(ServletConfig sc)
	{
        super.loadBus(sc);

		// Build default conf for Provider
		Properties conf = new Properties();
		Enumeration<String> e = sc.getServletContext().getInitParameterNames();

		for(String n = null; e.hasMoreElements();) {
			n = e.nextElement();
			conf.setProperty(n, sc.getServletContext().getInitParameter(n));
		}

		conf.setProperty("provider.contextPath", sc.getServletContext().getContextPath());

		// Init the Provider
		service = new ServiceImpl(
			sc.getServletContext().getRealPath("/"),
			this.getBus(),
			conf
		);
    }

	@Override
	public void destroyBus()
	{
		service.destroy();
		service = null;
		super.destroyBus();
	}
}

